@layout("/common/_curd/_container.html"){

<script type="text/javascript">
	var ctx = "${basePath}";
	var grid_selector = "#grid-table";
	var pager_selector = "#grid-pager";
	var dept  = ${deptid};
	var role = ${role};
	console.log(role)
	var mys = 0;
	if(role==8){
		mys = 4;
	}else if(role == 9){
		mys = 3;
	}else if(role == 10){
		mys = 2;
	}else if(role == 11){
		mys = 1;
	}

	$(function(){
		initGrid();
		initMenuBtn("btns", "${code}");
	});
	
	function initGrid(){
		var grid_url = ctx + "/${code}/list";
		var _colnames = ["订单号",
						"供应商",
						"类别",
						"操作员", 
						"分公司", 
						"创建时间",
            "状态ID",
						"状态",
						"备注",
		"操作"];
		var _colmodel = [{name:"id", index:"id", width:100},
						{name:"sname", index:"sname", width:100},
						{name:"type", index:"type", width:100,formatter:function (value, rows, index) {
								if(value ==2){
								    return "外购配件";
								}else if(value == 1){
								    return "精品装潢";
								}else {
								    return "未选择";
								}
                            }},
						{name:"uname", index:"uname", width:100},
						{name:"dname", index:"dname", width:100},
						{name:"addtime", index:"addtime", width:100,formatter:function (value, rows, index) {
							if(value !== ""){
								return value.substring(0,10);
							}
						}},
            {name:"status", index:"status",hidden:true, width:100},
						{name:"staname", index:"staname", width:100},
						{name:"remarks", index:"remarks", width:100},
            {name:"remarks", index:"remarks", width:200,formatter:function (value, rows, index) {
					var status =  index.status;
					var orderId = index.id;
					var role = '${role}';
                    var html = "";
                    var shhtml = ""
				if(status > -2 && status<5){
					shhtml += '<a class="btn  btn-success btn-xs" href="#" role="button" onclick="passShowInput('+orderId+","+status+')">审核通过</a>';
					shhtml += '<a class="btn btn-warning btn-xs" href="#" role="button" onclick="backShowInput('+orderId+","+100+')">审核不通过</a>';
//                    shhtml += '<a class="btn btn-danger btn-xs" href="#" role="button" onclick="backFirst('+orderId+')">退回修改</a>';
					if(role == 1 ){//超级管理员
						html = html + shhtml;
					}else if(role == 8){
						if(status==4){
							html = html + shhtml;
						}
					}else if(role == 9){
						if(status == 3){
							html = html + shhtml;
						}
					}else if(role == 10){
						if(status == 2){
							html = html + shhtml;
						}
					}else if(role == 11){
						if(status == 1){
							html = html + shhtml;
						}
					}
					return html;
				}else {
					return html;
				}

                }}
		];

		console.log(mys)

		if(mys > 0){
			jQuery(grid_selector).jqGrid({
				url : grid_url,
				shrinkToFit : true,
				colNames : _colnames,
				colModel : _colmodel,
				jsonReader : {id :"id"},
				pager : pager_selector,
				postData : {sort : "id",
					where:"{dept:"+dept+",status:"+mys+"}",
					order : "desc"}
			});
		}else{
			jQuery(grid_selector).jqGrid({
				url : grid_url,
				shrinkToFit : true,
				colNames : _colnames,
				colModel : _colmodel,
				jsonReader : {id :"id"},
				pager : pager_selector,
				postData : {sort : "id",
					where:"{dept:"+dept+"}",
					order : "desc"}
			});
		}

	}
</script>


	<!-- 配置 grid -->
	<div class="row">
		<div class="col-xs-12 tb-grid">
			<!-- 配置 查询 -->
			@ var _col=[
			@		{name:"供应商", index:"sname", type:"text"},
			@		{name:"采购类别", index:"type", type:"select_309"},
			@		{name:"操作员", index:"uname", type:"text"},
			@		{name:"分公司", index:"dname", type:"text"},
			@		{name:"发布时间(大于)",index:"addtime_dategt", type:"date"},
			@		{name:"发布时间(小于)",index:"addtime_datelt", type:"date"},
			@		{name:"状态", index:"status", type:"text"},
			@		{name:"备注", index:"remarks", type:"text"}
			@];
			@ include("/common/_function/_search.html",{"col":_col}){}
			<!-- 按钮 -->
			<!--<div class="welljq well-sm" id="btns"></div>-->
			<div class="welljq well-sm" id="btnsss">
				<button class="btn btn-xs btn-white " id="snOrderIn_adds" onclick="_add()">
					&nbsp;<li class=" fa fa-floppy-o bigger-120"></li>
					&nbsp;新增&nbsp;
				</button>
				&nbsp;
				<button class="btn btn-xs btn-white " id="snOrderIn_edits"  onclick="_edit()">&nbsp;<li class=" fa fa-pencil  bigger-120">
				</li>&nbsp;修改&nbsp;</button>&nbsp;<button class="btn btn-xs btn-white " id="snOrderIn_view">&nbsp;
				<li class=" fa fa-eye bigger-120"></li>
				&nbsp;查看&nbsp;</button>&nbsp;
				<button class="btn btn-xs btn-white " id="snOrderIn_removes" onclick="_remove()">&nbsp;
					<li class=" fa fa-times  bigger-120">
					</li>&nbsp;删除&nbsp;
				</button>&nbsp;

				<button class="btn btn-xs btn-white " id="no_pass" onclick="no_pass()">&nbsp;
					<li class="glyphicon glyphicon-time  bigger-120">
					</li>&nbsp;待审核&nbsp;
				</button>&nbsp;

				<button class="btn btn-xs btn-white " id="has_pass"  onclick="has_pass()">&nbsp;
					<li class=" glyphicon glyphicon-list-alt  bigger-120">
					</li>&nbsp;已审核&nbsp;
				</button>&nbsp;

				<button class="btn btn-xs btn-white " id="all_apply" onclick="all_apply()">&nbsp;
					<li class="glyphicon glyphicon-list  bigger-120">
					</li>&nbsp;所有申请&nbsp;
				</button>&nbsp;
			</div>
			<!-- grid -->
			<table id="grid-table"></table>
			<!-- 分页-->
			<div id="grid-pager"></div>
		</div>
	</div>

<style>
	.option{
		display: none;
		position: fixed;
		top:30%;
		left:40%;
		width:300px;
		height: 300px;
		border:1px solid grey;
	}
	.op_head{
		height: 30px;
		background-color: #00b3ee;
		text-align: center;
		line-height: 30px;
	}
</style>

<div class="option">
	<div class="op_head">
		<span style="color: white">审核意见</span>
	</div>
	<textarea id="option" class="form-control" id="" cols="30" rows="8"></textarea>
	<input type="hidden" id="this_orderId" value="">
	<input type="hidden" id="this_status" value="">
	<div style="text-align: center;margin-top: 20px">
		<a class="btn  btn-default" href="#" role="button" onclick="pass()">确定</a>
        &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
        <a class="btn  btn-default" href="#" role="button" onclick="cancel()">取消</a>
	</div>
</div>
<script>

    var ss = "pass"
	var role = '${role}';
	var mystatus = 1;
	if(role==8){
		mystatus = 4;
	}else if(role == 9){
		mystatus = 3;
	}else if(role == 10){
		mystatus = 2;
	}else if(role == 11){
		mystatus = 1;
	}
    cancel = function(){
        $(".option").hide();
    }

	no_pass = function () {
		$jqGrid.jqGrid("setGridParam", { postData: { sort : "id",where:"{status:"+mystatus+"}",order : "desc" }, page: 1 }).trigger("reloadGrid");
	}

	has_pass = function () {
		var myHas = mystatus +1;
		$jqGrid.jqGrid("setGridParam", { postData: { sort : "id",where:"{status:"+myHas+"}",order : "desc" }, page: 1 }).trigger("reloadGrid");

	}

	all_apply = function () {
		$jqGrid.jqGrid("setGridParam", { postData: { sort : "id",where:"{}",order : "desc" }, page: 1 }).trigger("reloadGrid");
	}


	passShowInput = function(orderId,status){
        if(status <5){
            status++;
        }
		$("#this_orderId").val(orderId);
        $("#this_status").val(status);
        $("#option").val("");
        $(".option").show();
        ss = "确定通过审核吗？";
	}

    backShowInput = function(orderId,status){
        ss = "确定退回申请吗？";
        if(status >0){
            status--;
        }
        $("#this_orderId").val(orderId);
        $("#this_status").val(status);
        $("#option").val("");
        $(".option").show();
    }

    backFirst = function(orderId){
        ss = "确定退回最初状态吗？";
        $("#this_orderId").val(orderId);
        $("#this_status").val(0);
        $("#option").val("");
        $(".option").show();
    }
	pass  = function(){
       var orderId =  $("#this_orderId").val();
       var status =  $("#this_status").val();
      var opstep = $("#option").val();
        layer.msg(ss, {
            time: 0 //不自动关闭
            ,btn: ['确定','取消']
            ,yes: function(){
                var ajaxData = {status:status,orderId:orderId}
                if(status == 2){
                    ajaxData.opstep1 = opstep;
				}else if(status ==3) {
                    ajaxData.opstep2 = opstep;
                }else if(status ==4) {
                    ajaxData.opstep3 = opstep;
                }else if(status ==5) {
                    ajaxData.opstep4 = opstep;
                }
                $.post("/snOrderIn/pass",ajaxData,function (res) {
                    if(res["success"]){
                        layer.msg("操作成功！", {shift: -1,time:500,end:function () {
                                $(".option").hide()
							$jqGrid.jqGrid("setGridParam", { postData: { sort : "id",where:"{status:"+mystatus+"}",order : "desc" }, page: 1 }).trigger("reloadGrid");
                            }});
                    }
                })

            }
        });

	}

    // back  = function(orderId,status){
    //     layer.msg('确定退回审核吗？', {
    //         time: 0 //不自动关闭
    //         ,btn: ['确定','取消']
    //         ,yes: function(){
    //             if(status > 1){
    //                 status--;
    //             }
    //             var ajaxData = {status:status,orderId:orderId}
    //             ajaxData.opstep1 = "HelloWorld"
    //             $.get("/snOrderIn/pass",ajaxData,function (res) {
    //                 if(res["success"]){
    //                     layer.msg("操作成功！", {shift: -1,time:500,end:function () {
    //                             $jqGrid.jqGrid("setGridParam", { postData: { sort : "id",order : "desc" }, page: 1 }).trigger("reloadGrid");
    //                         }});
    //                 }
    //             })
    //
    //         }
    //     });
    //
    // }

	_remove = function () {
		var ids = $("#grid-table").jqGrid("getGridParam", "selarrrow");
		var row = $("#grid-table").jqGrid('getRowData', ids.toString());
		if(ids.length>1){
			layer.msg("不允许修改多项")
			return false;
		}else if(ids.length<1){
			layer.msg("请选择要修改的项")
			return false;
		}
		if(row.status > 1){
			layer.msg("已经审核过，不允许删除")
			return false;
		}
		$.get("/snOrderIn/remove",{ids:ids.toString()},function (res) {
			 if(res["success"]){
				 layer.msg("删除！", {shift: -1,time:500,end:function () {
						 $jqGrid.jqGrid("setGridParam", { postData: { sort : "id",order : "desc" }, page: 1 }).trigger("reloadGrid");
					 }});
			 }
		 })
	}
	_edit = function () {
		var ids = $("#grid-table").jqGrid("getGridParam", "selarrrow");
		var row = $("#grid-table").jqGrid('getRowData', ids.toString());
		if(ids.length>1){
			layer.msg("不允许修改多项")
			return false;
		}else if(ids.length<1){
			layer.msg("请选择要修改的项")
			return false;
		}
		if(row.status > 1){
			layer.msg("已经审核过，不允许再修改")
			return false;
		}
		var index = layer.open({
			type: 2,
			title:'编辑',
			area: ['100%', '100%'],
			maxmin:true,
			shadeClose: true, //点击遮罩关闭
			content:  '/snOrderIn/edit/'+ids.toString(),
			end:function () {
				$jqGrid.jqGrid("setGridParam", { postData: { sort : "id",order : "desc" }, page: 1 }).trigger("reloadGrid");
			}
		});
		this.layerIndex = index;
	}

	_add = function () {
        var index = layer.open({
            type: 2,
            title:'新增',
            area: ['100%', '100%'],
            maxmin:true,
            shadeClose: true, //点击遮罩关闭
            content:  '/snOrderIn/add',
            end:function () {
                $jqGrid.jqGrid("setGridParam", { postData: { sort : "id",order : "desc" }, page: 1 }).trigger("reloadGrid");
            }
        });

        this.layerIndex = index;
    }
</script>
	<!-- 引入所需的js -->
	@include("/common/_listscript.html"){}
	
@}	